package com.zhongyu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhongyu.mapper.KehuMapper;
import com.zhongyu.pojo.Kehu;
import com.zhongyu.service.KehuService;
import com.zhongyu.vo.KehuVo;
import com.zhongyu.vo.PageResult;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import javax.annotation.Resource;
import java.util.List;

@Service("kehuService")
public class KehuServiceImpl extends ServiceImpl<KehuMapper, Kehu> implements KehuService {


    @Resource
    private KehuMapper kehuMapper;

    @Override
    public List<Kehu> searchAll() {
        return kehuMapper.selectList(null);
    }

    @Override
    public void add(Kehu kehu) {
        kehuMapper.insert(kehu);
    }

    @Override
    public void del(Integer id) {
        kehuMapper.deleteById(id);
    }

    @Override
    public void update(Kehu kehu) {
        kehuMapper.updateById(kehu);
    }

    @Override
    public PageResult searchAll(Integer pageNo, Integer pageSize, KehuVo kehuVo) {
        LambdaQueryWrapper<Kehu> lambdaQueryWrapper =Wrappers.<Kehu>lambdaQuery();
        lambdaQueryWrapper.like(!StringUtils.isEmpty(kehuVo.getName()),Kehu::getKehuName,kehuVo.getName())
                          .like(!StringUtils.isEmpty(kehuVo.getPhone()),Kehu::getKehuPhone,kehuVo.getPhone())
                          .like(!StringUtils.isEmpty(kehuVo.getAddress()),Kehu::getKehuAddress,kehuVo.getAddress())
                          .like(!StringUtils.isEmpty(kehuVo.getEmail()),Kehu::getKehuEmail,kehuVo.getEmail());
        Page page=new Page(pageNo,pageSize);
        List<Kehu> list=baseMapper.findAll(page,lambdaQueryWrapper);
        return new PageResult(list,page.getTotal());
    }


}
